************************************************************
* Project: Defending the Watchdogs                         *
* Authors: Jonathan A. Solis & Kelebogile Zvobgo           *
* Task: Main Analysis                                      *
* Date: 7/10/2022                                          *
* Software: Stata MP 17                                    *
************************************************************

*-------------------------------------------------------------------------------
*NOTE: Please contact Jonathan (jsolis@aiddata.wm.edu) if you have any questions
*-------------------------------------------------------------------------------

*##* Load Data
*-------------
clear 
cd "[insert path]"
use DefendingWatchdogs_Dataset
set more off

*##* Set up dataset for Analysis
*-------------------------------

*Special ado file
***search gr0002_3
*-> for lean1 scheme for figures

*Natural log gdppc variables
gen gdppc_ln=ln(gdppc)

*Give Malta a region/colonial background
replace region=5 if country=="Malta"
replace nawest=1 if country=="Malta"
replace colonized=0 if country=="Malta"
replace british=0 if country=="Malta"
replace french=0 if country=="Malta"
replace spanish=0 if country=="Malta"
replace port=0 if country=="Malta"

*Create Interactions*

*Judicial Independence (L&S)
gen lji_poly=lji*polyarchy
gen lji_gold=lji*gold

*Judicial Independence (VDEM)
gen vdem_poly_hc=vdem_ji*polyarchy
gen vdem_poly_const=jconstraint*polyarchy
gen vdem_gold=vdem_ji*gold

*Create Macros*

*DVs (w/ lag)
global mdcensor mdcensor l.mdcensor
global mdharass mdharass l.mdharass
global inetcen  inetcen  l.inetcen

*IV variables (LJI): simple model
global xlist_simple           l.lji l.polyarchy
global xlist_simple_gold      l.lji l.gold 
global xlist_simple_int       l.lji l.polyarchy l.lji_poly
global xlist_simple_gold_int  l.lji l.gold5 l.lji_gold

*IV variables (VDEM-hc): simple model
global xlist_simple_vd       l.vdem_ji l.polyarchy l.vdem_poly_hc
global xlist_simple_gold_vd  l.vdem_ji l.gold l.vdem_gold

*IV variables (VDEM-hc-ord): simple model
gen vdem_poly_hco=vdem_jiord*polyarchy
global xlist_simple_vdo       l.vdem_jiord l.polyarchy l.vdem_poly_hco
global xlist_simple_gold_vdo  l.vdem_jiord l.gold l.vdemo_gold

*IV variables: controls
global xlist_ctrls l.gmf_binary l.education l.KOFInGIdj l.gdppc_ln l.aid l.rents_wb l.conflict2 l.hrp_point

*IV variables: controls (minus gmf_binary: JHR request)
global xlist_ctrls_sansgmf l.education l.KOFInGIdj l.gdppc_ln l.aid l.rents_wb l.conflict2 l.hrp_point

*set as panel
xtset ccode year

******************************************************
********************|--------|************************
********************|ANALYSIS|************************
********************|--------|************************
******************************************************

*-------------------------------------------------------------*
*Scatter Plot (MOVED FROM MANUSCRIPT, TO Appendix: Section B)*
*-------------------------------------------------------------*
 
*Basic plot
graph twoway scatter lji polyarchy, msize(.5) scheme(lean1) ylabel(,nogrid) ///
legend(off) ytitle("Judicial Independence (Linzer & Staton)", ///
 size(small)) xtitle("Electoral Democracy (V-Dem)", size(small)) 
graph export "JI_Poly_Scatter.pdf", replace
 
*---------------------------------*
*Tabl 1 (manuscrip): Models w/ LJI*
*---------------------------------*

*BASIC MODELS (WITH INTERACTION)*
*-------------------------------*
xtreg mdcensor $xlist_simple_int i.year, fe vce(robust)
gen byte full_sample=e(sample)
est sto m1
estat ic
*AIC = 17696.3

xtreg mdharass $xlist_simple_int i.year, fe vce(robust)
est sto m3
estat ic
*AIC = 16747.71 

xtreg inetcen $xlist_simple_int i.year, fe vce(robust)
gen byte full_inet=e(sample)
est sto m5
estat ic
*AIC = 3525.443 

*FULL MODELS*
*-----------*
xtreg mdcensor $xlist_simple_int $xlist_ctrls i.year, fe vce(robust)
gen censor_sample= e(sample)
est sto m2
estat ic
*AIC = 9659.163 

xtreg mdharass $xlist_simple_int $xlist_ctrls i.year, fe vce(robust)
gen harass_sample= e(sample)
est sto m4
estat ic
*AIC = 8689.214

xtreg inetcen $xlist_simple_int $xlist_ctrls i.year, fe vce(robust)
gen inet_sample= e(sample)
est sto m6
estat ic
*AIC= 3114.207

****TABLE 1 (though I make some changes by hand)****
esttab m1 m2 m3 m4 m5 m6 using table1.tex, replace se aic ar2(3) obslast ///
mtitle("Trd. Media" "Trd. Media" "Harassment" "Harassment" "Internet" "Internet" ) ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" ///
 L.lji_poly "Jud. Ind.*Elec. Demo." L.gmf_binary "Open Media" L.vdem_edueq ///
 "Education" L.KOFInGIdj "Information Flows" L.gdppc_ln "ln(GDP p/c)" ///
 L.aid "Aid (\% GNI)" L.rents_wb "Resource Wealth" L.conflict2 ///
 "Conflict" L.hrp_point "Human Rights" L.mdcensor) ///
 varwidth(2) scalar(N_g) drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.3f) nolz

**********************************************************
*** FIND PERCENTAGE OF COUNTRIES ABOVE/BELOW THRESHOLD ***
**********************************************************

*Note: Get .87 and .54 from Figures 1a and 1b respectively (when marginal effect 
*      loses statistical significance at alpha .05) 

*Censorship
gen thresh_censor=.
replace thresh_censor=1 if polyarchy>.87 & censor_sample==1
replace thresh_censor=0 if thresh_censor==. & censor_sample==1
tab thresh_censor
*10.41%

*Harassment
gen thresh_harass=.
replace thresh_harass=1 if polyarchy>.54 & harass_sample==1
replace thresh_harass=0 if thresh_harass==. & harass_sample==1
tab thresh_harass
*43.07%

****************************************************************************
***|--------------------------------------------------------------------|***
***|Substantive Interpretations (seen throughout Main Results subsection|***
***|--------------------------------------------------------------------|***
****************************************************************************

********************
* * * * ** * * * * *
* MODEL 2 MDCENSOR *
* * * * ** * * * * * 
********************

*-> Judicial Independence

xtreg mdcensor $xlist_simple_int $xlist_ctrls i.year, fe vce(robust)
gen byte cen=e(sample)

*find 25% and 75% quartiles of IV (lji)
sum l.lji if cen==1, detail
*25%Q= .2201
*75%Q= .7304  

*constant
* _con = 1.983502
 
*Formula for lji levels @ 25% quartile

*y_hat(x_low) = lji_25%q*B1 + B2_constant
display (.2201*-2.381279) + 1.983502
* = 1.4593825

*y_hat(x_high) =  lji_75%q*B1 + B2_constant
display (.7304*-2.381279) + 1.983502
* = .24421582

*Distance, or change from 25%Q to 75%Q
display (1.4593825 - .24421582)*-1
* = -1.2151667

*Change from 25Q to 75Q over Y st. dev.
sum mdcensor if cen==1, detail
*St. Dev (mdcensor)= 1.581382
display -1.2151667/1.581382

* = -.76842072

*Substantive Result: A move from 25%Q to 75%Q results in a -76.8% change in the DV's standard deviation.

*-> Polyarchy

*find 25% and 75% quartiles of IV (polyarchy)
sum l.polyarchy if cen==1, detail
*25%Q= .198
*75%Q= .764

*constant
* _con = 1.983502
 
*Formula for polyarchy levels @ 25% quartile

*y_hat(x_low) = polyarchy_25%q*B1 + B2_constant
display (.198*-3.976297) +  1.983502
* = 1.1961952

*y_hat(x_high) =  polyarchy_75%q*B1 + B2_constant
display (.764 *-3.976297) +  1.983502 
* = -1.0543889

*Distance, or change from 25%Q to 75%Q
display (1.1961952 - -1.0543889)*-1
* = -2.2505841

*Change from 25Q to 75Q over Y st. dev.
sum mdcensor if cen==1, detail
*St. Dev (mdcensor)= 1.581382
display -2.2505841/1.581382

* = -1.4231755

*Substantive Result: A move from 25%Q to 75%Q results in a -142.3% change in the DV's standard deviation.

********************
* * * * ** * * * * *
* MODEL 4 MDHARASS *
* * * * ** * * * * * 
********************

*-> Judicial Independence

xtreg mdharass $xlist_simple_int $xlist_ctrls i.year, fe vce(robust)
gen byte harass=e(sample)

*find 25% and 75% quartiles of IV (lji)
sum l.lji if harass==1, detail
*25%Q= .2201
*75%Q= .7304

*constant
* _con = .7922426
 
*Formula for lji levels @ 25% quartile

*y_hat(x_low) = lji_25%q*B1 + B2_constant
display (.2201*-2.4577) + .7922426
* = .25130283

*y_hat(x_high) =  lji_75%q*B1 + B2_constant
display (.7304*-2.4577) + .7922426 
* = -1.0028615

*Distance, or change from 25%Q to 75%Q
display (.25130283 - -1.0028615)*-1
* = -1.2541643

*Change from 25Q to 75Q over Y st. dev.
sum mdharass if harass==1, detail
*St. Dev (mdharass)= 1.524143
display -1.2541643/1.524143

* = -.82286524

*Substantive Result: A move from 25%Q to 75%Q results in a -82.2% change in the DV's standard deviation.

*-> Polyarchy

*find 25% and 75% quartiles of IV (polyarchy)
sum l.polyarchy if harass==1, detail
*25%Q= .198
*75%Q= .764

*constant
* _con = .7922426
 
*Formula for polyarchy levels @ 25% quartile

*y_hat(x_low) = polyarchy_25%q*B1 + B2_constant
display (.198*-4.073401) +  .7922426  
* = -.0142908

*y_hat(x_high) =  lji_75%q*B1 + B2_constant
display (.764 *-4.073401) +  .7922426    
* = -2.3198358

*Distance, or change from 25%Q to 75%Q
display (-.0142908 - -2.3198358)*-1
* = -2.305545

*Change from 25Q to 75Q over Y st. dev.
sum mdharass if harass==1, detail
*St. Dev (mdharass)= 1.524143
display -2.305545/1.524143

* = -1.5126829

*Substantive Result: A move from 25%Q to 75%Q results in a -151.2% change in the DV's standard deviation.

**********************
* * * * ** * * * * * *
* MODEL 6 INETCENSOR *
* * * * ** * * * * * *
**********************

xtreg inetcen $xlist_simple_int $xlist_ctrls i.year, fe vce(robust)
gen byte inet=e(sample)

*-> Polyarchy

*find 25% and 75% quartiles of IV (polyarchy)
sum l.polyarchy if inet==1, detail
*25%Q= .307 
*75%Q= .796 

*constant
* _con = -.6402325
 
*Formula for polyarchy levels @ 25% quartile

*y_hat(x_low) = polyarchy_25%q*B1 + B2_constant
display (.307*-2.439854) + -.6402325  
* = -1.3892677

*y_hat(x_high) =  lji_75%q*B1 + B2_constant
display (.796 *-2.439854) +  -.6402325   
* = -2.5823563

*Distance, or change from 25%Q to 75%Q
display (-1.3892677 - -2.5823563)*-1
* = -1.1930886

*Change from 25Q to 75Q over Y st. dev.
sum inetcen if inet==1, detail
*St. Dev (inetcen)=1.335715
display -1.1930886/1.335715

* = -.89322093

*Substantive Result: A move from 25%Q to 75%Q results in a -89.3% change in the DV's standard deviation.
 
************************************************************
*==========================================================*
*----------------------------------------------------------*
************************************************************
***********ROBUSTNESS CHECKS (found in Appendix)************
************************************************************
*----------------------------------------------------------*
*==========================================================*
************************************************************

*I. Regional Models (Appendix H)

*-------*
*E. Euro*
*-------*

xtreg mdcensor $xlist_simple_int $xlist_ctrls i.year if eeuro==1, fe vce(robust)
est sto cenreg1

xtreg mdharass $xlist_simple_int $xlist_ctrls i.year if eeuro==1, fe vce(robust)
est sto harasreg1

xtreg inetcen $xlist_simple_int $xlist_ctrls i.year if eeuro==1, fe vce(robust)
est sto inetreg1

*----*
*LA-C*
*----*

xtreg mdcensor $xlist_simple_int $xlist_ctrls i.year if lac==1, fe vce(robust)
est sto cenreg2

xtreg mdharass $xlist_simple_int $xlist_ctrls i.year if lac==1, fe vce(robust)
est sto harasreg2

xtreg inetcen $xlist_simple_int $xlist_ctrls i.year if lac==1, fe vce(robust)
est sto inetreg2

*----*
*MENA*
*----*

xtreg mdcensor $xlist_simple_int $xlist_ctrls i.year if mena==1, vce(robust)
est sto cenreg3

xtreg mdharass $xlist_simple_int $xlist_ctrls i.year if mena==1, vce(robust)
est sto harasreg3

xtreg inetcen $xlist_simple_int $xlist_ctrls i.year if mena==1, fe vce(robust)
est sto inetreg3

*---*
*SSA*
*---*

xtreg mdcensor $xlist_simple_int $xlist_ctrls i.year if ssa==1, fe vce(robust)
est sto cenreg4

xtreg mdharass $xlist_simple_int $xlist_ctrls i.year if ssa==1, fe vce(robust)
est sto harasreg4

xtreg inetcen $xlist_simple_int $xlist_ctrls i.year if ssa==1, fe vce(robust)
est sto inetreg4

*------*
*NAWEST*
*------*

xtreg mdcensor $xlist_simple_int $xlist_ctrls i.year if nawest==1, fe vce(robust)
est sto cenreg5

xtreg mdharass $xlist_simple_int $xlist_ctrls i.year if nawest==1, fe vce(robust)
est sto harasreg5  

xtreg inetcen $xlist_simple_int $xlist_ctrls i.year if nawest==1, fe vce(robust)
est sto inetreg5

*----*
*ASIA*
*----*

xtreg mdcensor $xlist_simple_int $xlist_ctrls i.year if asia==1, fe vce(robust)
est sto cenreg6

xtreg mdharass $xlist_simple_int $xlist_ctrls i.year if asia==1, fe vce(robust)
est sto harasreg6

xtreg inetcen $xlist_simple_int $xlist_ctrls i.year if asia==1, fe vce(robust)
est sto inetreg6

****APPENDIX: REGIONAL CENSORSHIP (though I make some changes by hand)****
esttab cenreg1 cenreg2 cenreg3 cenreg4 cenreg5 cenreg6 using appx_cens_regioanl.tex,  replace se aic ar2(3) obslast ///
mtitle("E. Euro" "LA-C" "MENA" "SSA" "W. Euro/NA" "Asia" ) ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" L.lji_poly ///
"Jud. Ind.*Elec. Demo." L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj ///
"Information Flows" L.gdppc_ln "ln(GDP p/c)" L.aid "Aid (\% GNI)" L.rents_wb ///
"Resource Wealth" L.conflict2 "Conflict" L.hrp_point "Human Rights") ///
varwidth(2) scalar(N_g) ///
drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.3f) nolz

****APPENDIX: REGIONAL Md. HARASSMENT (though I make some changes by hand)****
esttab harasreg1 harasreg2 harasreg3 harasreg4 harasreg5 harasreg6 using appx_harass_regioanl.tex, replace se aic ar2(3) obslast ///
mtitle("E. Euro" "LA-C" "MENA" "SSA" "W. Euro/NA" "Asia" ) ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" L.lji_poly ///
"Jud. Ind.*Elec. Demo." L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj ///
"Information Flows" L.gdppc_ln "ln(GDP p/c)" L.aid "Aid (\% GNI)" L.rents_wb ///
"Resource Wealth" L.conflict2 "Conflict" L.hrp_point "Human Rights") ///
varwidth(2) scalar(N_g) ///
drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.3f) nolz

****APPENDIX: REGIONAL INTERNET CENSORSHIP (though I make some changes by hand)****
esttab inetreg1 inetreg2 inetreg3 inetreg4 inetreg5 inetreg6 using appx_inet_regioanl.tex, replace se aic ar2(3) obslast ///
mtitle("E. Euro" "LA-C" "MENA" "SSA" "W. Euro/NA" "Asia" ) ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" L.lji_poly ///
"Jud. Ind.*Elec. Demo." L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj ///
"Information Flows" L.gdppc_ln "ln(GDP p/c)" L.aid "Aid (\% GNI)" L.rents_wb ///
"Resource Wealth" L.conflict2 "Conflict" L.hrp_point "Human Rights") ///
 varwidth(2) scalar(N_g) ///
drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.3f) nolz


*II. Alternative Demo Variable, Goldstone et al. (Appendix E)
 
*Judicial Independence (L&S)
gen lji_gold5=lji*gold5

*IV variables (LJI): simple model
global xlist_simple_gold5      l.lji l.gold5 
global xlist_simple_gold5_int  l.lji l.gold5 l.lji_gold5

*BASIC MODELS
xtreg mdcensor $xlist_simple_gold5_int $xlist_ctrls i.year, fe vce(robust)
est sto altdem1
xtreg mdharass $xlist_simple_gold5_int $xlist_ctrls i.year, fe vce(robust) 
est sto altdem2
xtreg inetcen $xlist_simple_gold5_int $xlist_ctrls i.year, fe vce(robust)
est sto altdem3

****APPENDIX: ALT. DEMO MEASURES (though I make some changes by hand)****
esttab altdem1 altdem2 altdem3 using appx_altdemo.tex, replace se aic obslast ar2(3) ///
mtitle("Trd. Media" "Harassment" "Internet"  ) ///
coeflabel(L.lji "Judicial Independence" L.gold5 "Elec. Dem. (Goldstein et al.)" ///
L.lji_gold5 "Jud. Ind.*Gold" L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj ///
"Information Flows" L.gdppc_ln "ln(GDP p/c)" L.aid "Aid (\% GNI)" L.rents_wb ///
"Resource Wealth" L.conflict2 "Conflict" L.hrp_point "Human Rights") ///
 varwidth(2) scalar(N_g) drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.3f) nolz

 
*III. Alternative JI Variable, V-Dem: Judicial Constraint (Appendix F)

*BASIC MODELS
xtreg mdcensor $xlist_simple_vd  $xlist_ctrls i.year, fe vce(robust)
est sto jivdem1
xtreg mdharass $xlist_simple_vd $xlist_ctrls i.year, fe vce(robust)
est sto jivdem2
xtreg inetcen $xlist_simple_vd $xlist_ctrls i.year, fe vce(robust)
est sto jivdem3

****APPENDIX: ALT. JI MEASURES (though I make some changes by hand)****
esttab jivdem1 jivdem2 jivdem3 using appx_altji.tex, replace se aic obslast ar2 ///
mtitle("Trd. Media" "Harassment" "Internet") ///
coeflabel(L.vdem_ji "Judicial Independence" L.polyarchy "Electoral Democracy" L.vdem_poly_hc ///
"Jud. Ind.*Elec. Demo." L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj ///
"Information Flows" L.gdppc_ln "ln(GDP p/c)" L.aid "Aid (\% GNI)" L.rents_wb ///
"Resource Wealth" L.conflict2 "Conflict" L.hrp_point "Human Rights") ///
varwidth(2) scalar(N_g) drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.3f) nolz


*IV. Economic (Appendix I.1)

*Add: Fdi, GDP, GDP change
gen gdp_ln=ln(gdp)
gen fdi_ln=ln(fdi)
replace fdi_ln=0 if fdi==0

*Create economic macros
global economic l.fdi_ln l.gdp_ln l.gdppc_cng 

*BASIC MODELS
xtreg mdcensor $xlist_simple_int $xlist_ctrls $economic i.year, fe vce(robust)
est sto econ1 
xtreg mdharass $xlist_simple_int $xlist_ctrls $economic i.year, fe vce(robust)
est sto econ2
xtreg inetcen $xlist_simple_int $xlist_ctrls $economic i.year, fe vce(robust)
est sto econ3

*IVb. Composite Index of National Capabilities (CINC)

*Add: cinc(ln)
gen cinc_ln=ln(cinc)

*BASIC MODELS
xtreg mdcensor $xlist_simple_int $xlist_ctrls l.cinc_ln i.year, fe vce(robust)
est sto econ4 
xtreg mdharass $xlist_simple_int $xlist_ctrls l.cinc_ln i.year, fe vce(robust)  
est sto econ5 
xtreg inetcen $xlist_simple_int $xlist_ctrls l.cinc_ln i.year, fe vce(robust) 
est sto econ6  

****APPENDIX: ECONOMIC MEASURES (though I make some changes by hand)****
esttab econ1 econ2 econ3 econ4 econ5 econ6 using appx_econ.tex, replace se aic obslast ar2(3) ///
mtitle("Trd. Media" "Trd. Media" "Harassment" "Harassment" "Internet" "Internet") ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" L.lji_poly ///
"Jud. Ind.*Elec. Demo." L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj ///
"Information Flows" L.gdppc_ln "ln(GDP p/c)" L.aid "Aid (\% GNI)" L.rents_wb ///
"Resource Wealth" L.conflict2 "Conflict" L.hrp_point "Human Rights" L.fdi_ln ///
 "ln(FDI)" L.gdp_ln "ln(GDP)" L.gdppc_cng "GDP p/c \delta"  L.cinc_ln "ln(CINC)") ///
varwidth(2) scalar(N_g) drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.2f) nolz

*V. Colonial History (Appendix I.2)

*Va. If colonized

*BASIC MODELS
xtreg mdcensor $xlist_simple_int $xlist_ctrls colonized i.year cfe*, vce(robust)
est sto colony1
*Get adj. R2
reg mdcensor $xlist_simple_int $xlist_ctrls colonized i.year cfe*, vce(robust)
display  e(r2_a) 

xtreg mdharass $xlist_simple_int $xlist_ctrls colonized i.year cfe*, vce(robust)
est sto colony2
*Get adj. R2
reg mdharass $xlist_simple_int $xlist_ctrls colonized i.year cfe*, vce(robust)
display  e(r2_a) 

xtreg inetcen $xlist_simple_int $xlist_ctrls colonized i.year cfe*, vce(robust)
est sto colony3 
*Get adj. R2
reg inetcen $xlist_simple_int $xlist_ctrls colonized i.year cfe*, vce(robust)
display  e(r2_a) 

*Vb. Colonizer dummies

*Create colonial macro
global colonial british french spanish port

*BASIC MODELS
xtreg mdcensor $xlist_simple_int $xlist_ctrls $colonial i.year cfe*, vce(robust)
est sto colony4
*Get adj. R2
reg mdcensor $xlist_simple_int $xlist_ctrls $colonial i.year cfe*, vce(robust)
display  e(r2_a) 

xtreg mdharass $xlist_simple_int $xlist_ctrls $colonial i.year cfe*, vce(robust)
est sto colony5
*Get adj. R2
reg mdharass $xlist_simple_int $xlist_ctrls $colonial i.year cfe*, vce(robust)
display  e(r2_a) 

xtreg inetcen $xlist_simple_int $xlist_ctrls $colonial i.year cfe*, vce(robust)
est sto colony6
*Get adj. R2
reg inetcen $xlist_simple_int $xlist_ctrls $colonial i.year cfe*, vce(robust)
display  e(r2_a) 

****APPENDIX: COLONIAL BACKGROUND (though I make some changes by hand)****
esttab colony1 colony2 colony3 colony4 colony5 colony6 using appx_colony.tex, replace se aic obslast r2 ar2(3) ///
mtitle("Trd. Media" "Harassment" "Internet" "Trd. Media"  "Harassment"  "Internet") ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" L.lji_poly ///
"Jud. Ind.*Elec. Demo." L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj ///
"Information Flows" L.gdppc_ln "ln(GDP p/c)" L.aid "Aid (\% GNI)" L.rents_wb ///
"Resource Wealth" L.conflict2 "Conflict" L.hrp_point "Human Rights" ///
british "British" french "French" spanish "Spanish" port "Portugal" colonized "Colonized") ///
varwidth(2) scalar(N_g) drop(1* 2* cfe* _cons) b(%9.3f) t(%9.3f) r2(%9.2f) nolz

*VI. Political Climate (Appendix I.3)

*Add: Coup, election, boycott

*VIa. Coup types

*Create macros for coup analysis
global coup_indv l.suc_coup l.atmp_coup l.plt_coup l.alg_plt 

xtreg mdcensor $xlist_simple_int $xlist_ctrls $coup_indv i.year, fe vce(robust) 
est sto coup1
xtreg mdharass $xlist_simple_int $xlist_ctrls $coup_indv i.year, fe vce(robust) 
est sto coup2
xtreg inetcen $xlist_simple_int $xlist_ctrls $coup_indv i.year, fe vce(robust) 
est sto coup3

*VIb. Unsuccesful Coups (atmp_coup + plt_coup + alg_plt)
xtreg mdcensor $xlist_simple_int $xlist_ctrls l.coup_unsucsfl i.year, fe vce(robust)
est sto coup4
xtreg mdharass $xlist_simple_int $xlist_ctrls l.coup_unsucsfl i.year, fe vce(robust)
est sto coup5
xtreg inetcen $xlist_simple_int $xlist_ctrls l.coup_unsucsfl i.year, fe vce(robust)
est sto coup6

*VIc. Coup events
xtreg mdcensor $xlist_simple_int $xlist_ctrls l.coup_events i.year, fe vce(robust)
est sto coup7
xtreg mdharass $xlist_simple_int $xlist_ctrls l.coup_events i.year, fe vce(robust) 
est sto coup8
xtreg inetcen $xlist_simple_int $xlist_ctrls l.coup_events i.year, fe vce(robust)
est sto coup9

****APPENDIX: COUPS (though I make some changes by hand)****
esttab coup1 coup2 coup3 coup4 coup5 coup6 coup7 coup8 coup9 using appx_coup.tex, replace se aic obslast r2 ar2(3) ///
mtitle("Trd. Media" "Harassment" "Internet" "Trd. Media" "Harassment" "Internet" "Trd. Media" "Harassment" "Internet" ) ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" L.lji_poly "Jud. Ind.*Elec. Demo." ///
 L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj "Information Flows" L.gdppc_ln "ln(GDP p/c)" ///
 L.aid "Aid (\% GNI)" L.rents_wb "Resource Wealth" L.conflict2 "Conflict" L.hrp_point "Human Rights" ///
 L.suc_coup "Successful Coups" L.atmp_coup "Attempted Coups" L.plt_coup "Plotted Coups" L.alg_plt ///
 "Alleged Coups" L.coup_unsucsfl "Unsuccessful Coups" L.coup_events "Coup Events" ) varwidth(2) scalar(N_g) ///
drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.2f) nolz

*VIId. Pres Elections (Appendix I.4)
xtreg mdcensor $xlist_simple_int $xlist_ctrls l.pres_elect i.year, fe vce(robust)
est sto elec1
xtreg mdharass $xlist_simple_int $xlist_ctrls l.pres_elect i.year, fe vce(robust)
est sto elec2
xtreg inetcen $xlist_simple_int $xlist_ctrls l.pres_elect i.year, fe vce(robust) 
est sto elec3

*VIIe. National Elections (Appendix I.4)
xtreg mdcensor $xlist_simple_int $xlist_ctrls l.ntl_elect i.year, fe vce(robust)
est sto elec4
xtreg mdharass $xlist_simple_int $xlist_ctrls l.ntl_elect i.year, fe vce(robust)
est sto elec5
xtreg inetcen $xlist_simple_int $xlist_ctrls l.ntl_elect i.year, fe vce(robust)
est sto elec6 

****APPENDIX: ELECTIONS (though I make some changes by hand)****
esttab elec1 elec2 elec3 elec4 elec5 elec6 using appx_elect.tex, replace se aic obslast r2 ar2(3) ///
mtitle("Trd. Media" "Harassment" "Internet" "Trd. Media" "Harassment" "Internet" "Trd. Media" "Harassment" "Internet" ) ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" L.lji_poly "Jud. Ind.*Elec. Demo." ///
 L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj "Information Flows" L.gdppc_ln "ln(GDP p/c)" ///
 L.aid "Aid (\% GNI)" L.rents_wb "Resource Wealth" L.conflict2 "Conflict" L.hrp_point "Human Rights" ///
 L.pres_elect "Presidential Election" L.ntl_elect "National Election") varwidth(2) scalar(N_g) ///
drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.2f) nolz

*VIIf. Boycott national elections (Appendix I.5)
xtreg mdcensor $xlist_simple_int $xlist_ctrls l.boycot i.year, fe vce(robust)
est sto boycot1
xtreg mdharass $xlist_simple_int $xlist_ctrls l.boycot i.year, fe vce(robust)
est sto boycot2
xtreg inetcen $xlist_simple_int $xlist_ctrls l.boycot i.year, fe vce(robust)
est sto boycot3 

****APPENDIX: BoycottedELECTIONS (though I make some changes by hand)****
esttab boycot1 boycot2 boycot3 using appx_boycot.tex, replace se aic obslast r2 ar2(3) ///
mtitle("Trd. Media" "Harassment" "Internet" "Trd. Media" "Harassment" "Internet" "Trd. Media" "Harassment" "Internet" ) ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" L.lji_poly "Jud. Ind.*Elec. Demo." ///
 L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj "Information Flows" L.gdppc_ln "ln(GDP p/c)" ///
 L.aid "Aid (\% GNI)" L.rents_wb "Resource Wealth" L.conflict2 "Conflict" L.hrp_point "Human Rights" ///
 L.boycot "National Elec. Boycott") varwidth(2) scalar(N_g) ///
drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.2f) nolz

*VIIg. Violent protests (Appendix I.6)
xtreg mdcensor $xlist_simple_int $xlist_ctrls l.viol_prts i.year, fe vce(robust)
est sto prot1
xtreg mdharass $xlist_simple_int $xlist_ctrls l.viol_prts i.year, fe vce(robust)
est sto prot2
xtreg inetcen $xlist_simple_int $xlist_ctrls l.viol_prts i.year, fe vce(robust)
est sto prot3 

*VIIh. Non-Violent protests (Appendix I.6)
xtreg mdcensor $xlist_simple_int $xlist_ctrls l.nonviol_prts i.year, fe vce(robust)
est sto prot4
xtreg mdharass $xlist_simple_int $xlist_ctrls l.nonviol_prts i.year, fe vce(robust)
est sto prot5
xtreg inetcen $xlist_simple_int $xlist_ctrls l.nonviol_prts i.year, fe vce(robust)
est sto prot6 

****APPENDIX: PROTESTS(though I make some changes by hand)****
esttab prot1 prot2 prot3 prot4 prot5 prot6 using appx_prot.tex, replace se aic obslast r2 ar2(3) ///
mtitle("Trd. Media" "Harassment" "Internet" "Trd. Media" "Harassment" "Internet" "Trd. Media" "Harassment" "Internet" ) ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" L.lji_poly "Jud. Ind.*Elec. Demo." ///
 L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj "Information Flows" L.gdppc_ln "ln(GDP p/c)" ///
 L.aid "Aid (\% GNI)" L.rents_wb "Resource Wealth" L.conflict2 "Conflict" L.hrp_point "Human Rights" ///
 L.viol_prts "Violent Protests" L.prts_size "Protest Size" L.nonviol_prts "Non-Violent Protests") ///
 varwidth(2) scalar(N_g) drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.2f) nolz

*VIIi. Cold War (Appendix I.7)
*Simple model
xtreg mdcensor $xlist_simple_int  coldwar i.year, fe vce(robust)
est sto cw1
xtreg mdharass $xlist_simple_int coldwar i.year, fe vce(robust)
est sto cw2
*W/ controls
xtreg mdcensor $xlist_simple_int $xlist_ctrls coldwar i.year, fe vce(robust)
est sto cw3
xtreg mdharass $xlist_simple_int $xlist_ctrls coldwar i.year, fe vce(robust)
est sto cw4

****APPENDIX: Cold War****
esttab cw1 cw2 cw3 cw4 using appx_cw.tex, replace se aic obslast r2 ar2(3) ///
mtitle("Trd. Media" "Harassment" "Trd. Media" "Harassment" ) ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" L.lji_poly "Jud. Ind.*Elec. Demo." ///
 L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj "Information Flows" L.gdppc_ln "ln(GDP p/c)" ///
 L.aid "Aid (\% GNI)" L.rents_wb "Resource Wealth" L.conflict2  "Conflict"  L.hrp_point "Human Rights" /// 
coldwar "Cold War") varwidth(2) scalar(N_g) drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.2f) nolz

*VIIj. Gov't attack on Judicary (Appendix I.8)
xtreg mdcensor $xlist_simple_int $xlist_ctrls l.jud_atckord i.year, fe vce(robust)
est sto jud_atk1
xtreg mdharass $xlist_simple_int $xlist_ctrls l.jud_atckord i.year, fe vce(robust)
est sto jud_atk2
xtreg inetcen $xlist_simple_int $xlist_ctrls l.jud_atckord i.year, fe vce(robust) 
est sto jud_atk3

****APPENDIX: Gov't attacking Judiciary****
esttab jud_atk1 jud_atk2 jud_atk3 using appx_judatk.tex, replace se aic obslast r2 ar2(3) ///
mtitle("Trd. Media" "Harassment" "Internet" "Trd. Media" "Harassment" "Internet" "Trd. Media" "Harassment" "Internet" ) ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" L.lji_poly "Jud. Ind.*Elec. Demo." ///
 L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj "Information Flows" L.gdppc_ln "ln(GDP p/c)" ///
 L.aid "Aid (\% GNI)" L.rents_wb "Resource Wealth" L.conflict2 "Conflict"  L.hrp_point "Human Rights" /// 
 L.jud_atckprd "Gov't Attack Crts.") varwidth(2) scalar(N_g) drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.2f) nolz

*VIIk. Divided gov't (Appendix I.9)
xtreg mdcensor $xlist_simple_int $xlist_ctrls l.vdem_divgvt i.year, fe vce(robust)
est sto div1
xtreg mdharass $xlist_simple_int $xlist_ctrls l.vdem_divgvt i.year, fe vce(robust)
est sto div2
xtreg inetcen $xlist_simple_int $xlist_ctrls  l.vdem_divgvt i.year, fe vce(robust) 
est sto div3

****APPENDIX: Gov't Divided****
esttab div1 div2 div3 using appx_divgov.tex, replace se aic obslast r2 ar2(3) ///
mtitle("Trd. Media" "Harassment" "Internet" ) ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" L.lji_poly "Jud. Ind.*Elec. Demo." ///
 L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj "Information Flows" L.gdppc_ln "ln(GDP p/c)" ///
 L.aid "Aid (\% GNI)" L.rents_wb "Resource Wealth" L.conflict2 "Conflict" L.hrp_point "Human Rights" ///
 L.vdem_divgvt "Divided Govt") varwidth(2) scalar(N_g) drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.2f) nolz

*VIIl. Political Constraints (Henisz) (Appendix I.10)
xtreg mdcensor $xlist_simple_int $xlist_ctrls l.polconiii i.year, fe vce(robust)
est sto pcon1
xtreg mdharass $xlist_simple_int $xlist_ctrls l.polconiii i.year, fe vce(robust)
est sto pcon2
xtreg inetcen $xlist_simple_int $xlist_ctrls  l.polconiii i.year, fe vce(robust) 
est sto pcon3

****APPENDIX: Political Constrains****
esttab pcon1 pcon2 pcon3 using appx_pcon.tex, replace se aic obslast r2 ar2(3) ///
mtitle("Trd. Media" "Harassment" "Internet" ) ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" L.lji_poly "Jud. Ind.*Elec. Demo." ///
 L.gmf_binary "Open Media" L.education "Education" L.KOFInGIdj "Information Flows" L.gdppc_ln "ln(GDP p/c)" ///
 L.aid "Aid (\% GNI)" L.rents_wb "Resource Wealth" L.conflict2 "Conflict"  L.hrp_point "Human Rights" ///
 L.polconiii "Political Constraints") varwidth(2) scalar(N_g) drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.2f) nolz

***************************************************
*********** Other Analyses in Appendix ************
***************************************************

*Summary Statistics (Section A.1/A.2)*

*NOTE: Need to run robustness checkmodels above for this to work (to get ln of 
*      certain variables)

*-> Base Models (1949-2016)
sum mdharass mdselfcen inetcen lji polyarchy if inrange(year,1949,2016)

*-> Full Models (1971-2016)
sum mdharass mdcensor inetcen lji polyarchy gmf_binary education KOFInGIdj gdppc_ln  ///
aid rents_wb conflict2 hrp_point if inrange(year,1971,2016)

*-> Robustness Checks (1971-2016)
sum gold5 vdem_ji fdi_ln gdp_ln gdppc_cng cinc_ln colonized ///
british french spanish port suc_coup atmp_coup plt_coup alg_plt /// 
coup_unsucsfl coup_events pres_elect ntl_elect boycot viol_prts ///
nonviol_prts coldwar jud_atckord vdem_divgvt polconiii if inrange(year,1971,2016)

 *****************
*PW-CORRELATIONS* 
*****************

*Democrcacy Variables (all, to 2008)

pwcorr polyarchy gold5 bmr dd

*             | polyar~y    gold5      bmr       dd
*-------------+------------------------------------
*   polyarchy |   1.0000 
*       gold5 |   0.8074   1.0000 
*         bmr |   0.8411   0.7625   1.0000 
*          dd |   0.8297   0.7892   0.9101   1.0000

*Democrcacy Variables (1970-2012)

pwcorr polyarchy gold5 bmr dd if year>1970

*             | polyar~y    gold5      bmr       dd
*-------------+------------------------------------
*   polyarchy |   1.0000 
*       gold5 |   0.8663   1.0000 
*         bmr |   0.8609   0.7854   1.0000 
*          dd |   0.8336   0.7753   0.8965   1.0000 


******************************************************
******************************************************
***********Correlations of DVs************************
******************************************************
******************************************************

pwcorr mdcensor mdharass
pwcorr mdcensor mdharass inetcen

corr mdcensor mdharass inetcen if inrange(year,1970,2015) &lji!=.
pwcorr mdcensor mdharass inetcen if inrange(year,1970,2015) &lji!=.

/****************************************

 Get coutries and years for list by region

*******************************************/

tab country if eeuro==1 & full_sample==1
tab country if lac==1 & full_sample==1
tab country if mena==1 & full_sample==1
tab country if ssa==1 & full_sample==1
tab country if nawest==1 & full_sample==1
tab country if asia==1 & full_sample==1

***************************************
***************************************
************* Supp. Code **************
***************************************
***************************************

*Investigate outliers: Residuals and Cooks distance (Section B, Apendix)

*-> bivariate regression (number of outliers decreases when dv/iv flips)
pwcorr lji polyarchy

*-> bivariate regression (number of outliers decreases when dv/iv flips)
reg lji polyarchy

* -> figure 
graph twoway (scatter lji polyarchy, msize(.5) mcolor(black)), scheme(lean1) ///
 ylabel( ,nogrid)  legend(off) ytitle("Judicial Independence (Linzer & Staton)", ///
 size(small)) xtitle("Electoral Democracy (V-Dem)", size(small))
graph export "JI_poly_figure.pdf", replace

*-> get Cook's distance and residuals
predict cook, cooksd, if e(sample)
sum cook 

*-> get residuals
*predict residuals, residuals 
*sum residuals

*list outliers
clist country year lji polyarchy cook if cook>4/9652 & cook!=., noobs
*-> label these outliers
gen outlier=1 if cook>4/9373 & cook!=.
replace outlier=0 if outlier!=1 & cook!=.

*-> generate rank of Cook's distance
* sort highest to lowest Cook's distance
gsort -cook
* assign a rank
generate rank =_n
* label every 35 for figure
gen byte sample_cd = mod(_n, 35) == 0 
replace sample_cd=. if outlier!=1
*- > create country, year label for figure
tostring year, generate(t)
gen label=country+ "," + t
drop t

*list top outliers
clist rank country year lji polyarchy if cook>4/9373 & cook!=., noobs

* -> figure with select outliers
graph twoway (scatter lji polyarchy if sample_cd==1, msize(.5) mcolor(black) ///
mlabsize(2) mlabel(label)) (lfitci lji polyarchy, lpattern(solis)), scheme(lean1) ///
 ylabel( ,nogrid)  legend(off) ytitle("Judicial Independence (Linzer & Staton)", ///
 size(small)) xtitle("Electoral Democracy (V-Dem)", size(small))
graph export "outliers.pdf", replace

*********************************************
**** ADDITIONAL CHECKS FROM JHR REFEREES ****
*********************************************

*** I. Task: See if Results in Table 1 hold when limited to 1993-2016 (Appendix G)

*RESULT: They do.

*-------------*
*Models w/ LJI*
*-------------*

*BASIC MODELS (WITH INTERACTION)*
*-------------------------------*
xtreg mdcensor $xlist_simple_int i.year if year>=1993, fe vce(robust)
gen byte full_sample_trnc=e(sample)
est sto m1_trnc
estat ic
*AIC = 4336.17 

xtreg mdharass $xlist_simple_int i.year if year>=1993, fe vce(robust)
est sto m3_trnc
estat ic
*AIC = 2957.778  

*FULL MODELS*
*-----------*
xtreg mdcensor $xlist_simple_int $xlist_ctrls i.year if year>=1993, fe vce(robust)
gen censor_sample_trnc= e(sample)
est sto m2_trnc
estat ic
*AIC = 3799.217 

xtreg mdharass $xlist_simple_int $xlist_ctrls i.year if year>=1993, fe vce(robust)
gen harass_sample_trnc= e(sample)
est sto m4_trnc
estat ic
*AIC = 2477.249

****TABLE 1 (though I make some changes by hand)****
esttab m1_trnc m2_trnc m3_trnc m4_trnc using table1_trnc.tex, replace se aic ar2(3) obslast ///
mtitle("Trd. Media" "Trd. Media" "Harassment" "Harassment") ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" ///
 L.lji_poly "Jud. Ind.*Elec. Demo." L.gmf_binary "Open Media" L.vdem_edueq ///
 "Education" L.KOFInGIdj "Information Flows" L.gdppc_ln "ln(GDP p/c)" ///
 L.aid "Aid (\% GNI)" L.rents_wb "Resource Wealth" L.conflict2 ///
 "Conflict" L.hrp_point "Human Rights" L.mdcensor) ///
 varwidth(2) scalar(N_g) drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.3f) nolz


*** II. Task: Remove GMF from controls (Appendix I.11)

*FULL MODELS*
*-----------*
xtreg mdcensor $xlist_simple_int $xlist_ctrls_sansgmf i.year, fe vce(robust)
*gen censor_sampleB= e(sample)
est sto m1b
estat ic
*AIC = 9663.395 

xtreg mdharass $xlist_simple_int $xlist_ctrls_sansgmf i.year, fe vce(robust)
*gen harass_sampleB= e(sample)
est sto m2b
estat ic
*AIC = 8693.508 

xtreg inetcen $xlist_simple_int $xlist_ctrls_sansgmf i.year, fe vce(robust)
*gen inet_sampleB= e(sample)
est sto m3b
estat ic
*AIC= 3112.237

****TABLE  (though I make some changes by hand)****
esttab m1b m2b m3b using table1_sansgmf.tex, replace se aic ar2(3) obslast ///
mtitle("Trd. Media" "Harassment" "Internet" ) ///
coeflabel(L.lji "Judicial Independence" L.polyarchy "Electoral Democracy" ///
 L.lji_poly "Jud. Ind.*Elec. Demo." L.vdem_edueq ///
 "Education" L.KOFInGIdj "Information Flows" L.gdppc_ln "ln(GDP p/c)" ///
 L.aid "Aid (\% GNI)" L.rents_wb "Resource Wealth" L.conflict2 ///
 "Conflict" L.hrp_point "Human Rights" L.mdcensor) ///
 varwidth(2) scalar(N_g) drop(1* 2* _cons) b(%9.3f) t(%9.3f) r2(%9.3f) nolz



